package eu.codlab.mouse_client;

import android.app.Fragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

public class MouseFragment extends Fragment{

	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View mainView = inflater.inflate(R.layout.mouse, container, false);		
		return mainView;

	}


	@Override
	public void onViewCreated(final View v, Bundle saved){
		SharedPreferences p = this.getActivity().getSharedPreferences("MOUSE_PREFS", 0);
		String server = p.getString("ip","");
		int ip = Integer.parseInt(p.getString("port","20007"));
		Client c = new Client(server, ip);
		if(!c.init()){
			this.getActivity().runOnUiThread(new Runnable(){
				public void run(){
					Toast.makeText(MouseFragment.this.getActivity(), R.string.peerfailed, Toast.LENGTH_LONG).show();
				}
			});
		}
			
		server = null;
		c = null;
	}

	public void onPause(){
		super.onPause();
	}

	public void onResume(){
		super.onResume();
	}

	public void onDestroy(){
		super.onDestroy();
	}
}
